const BaseIpcHandler = require('../BaseIpcHandler');

class CaptureMapHandler extends BaseIpcHandler {
    async handle(event, params) {
        // 解析参数
        // console.log('>> NewWndHandler params = ', params);
        const { lat, lng, alt, zoom, crop, scaleFactor } = JSON.parse(params.capture);

        // 业务逻辑
        let result = { code: -1, msg: 'Open app without electron!' };
        const ELECTRON_ENV = process.env.ELECTRON_ENV;
        if (ELECTRON_ENV) {
            result = this.app.mapwnd.captureMaps(lat, lng, alt, zoom, crop, scaleFactor);
        }

        // 返回结果
        if (event.from === 'localserver') {
            event.resp.send(result);
        } else {
            return result;
        }
    }
}

module.exports = CaptureMapHandler;
